﻿/**
* File: TpmmessageController.cs
* Author: 汪杰
* Create Time:2025/5/8 9:07:53
* Email:15200358008@139.com
* 代码由TMCodeGenerator自动生成
**/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using JSLCloud.App.Models.Tpmmessage;
using JSLCloud.App.Mes.Service;
using JSLCloud.Models;
using JSLCloud.Framework;

namespace JSLCloud.App.Mes.Controllers
{
    /// <summary>
    /// t_pm_message Controller
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class TpmmessageController : ControllerBase
    {
        private readonly ITpmmessageService _service;
        
        /// <summary>
        /// 默认构造函数
        /// </summary>
        public TpmmessageController(ITpmmessageService service)
        {
            _service = service;
        }
        
        /// <summary>
        /// 获取t_pm_message数据表数据
        /// </summary>
        /// <param name="requestObject">返回响应结果</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResponseObject<List<TpmmessageQueryModel>>> Get(string requestObject)
        {
            var request = JsonConvert.DeserializeObject<RequestGet>(requestObject);
            var user = TokenManager.GetCurentUserbyToken(Request.Headers);
            return await _service.GetAsync(request,user);
        }
        
        /// <summary>
        /// 新增t_pm_message数据表数据，支持批量新增
        /// </summary>
        /// <param name="requestObject">返回响应结果</param>
        [HttpPost]
        [HttpOptions]
        public async Task<ResponseObject<bool>> Post(RequestPost<TpmmessageAddModel> requestObject)
        {
            var user = TokenManager.GetCurentUserbyToken(Request.Headers);
            
            return await _service.PostAsync(requestObject);
        }
        
        /// <summary>
        /// 修改t_pm_message数据表数据，支持批量修改
        /// </summary>
        /// <param name="requestObject">返回响应结果</param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ResponseObject<bool>> Put(RequestPut<TpmmessageEditModel> requestObject)
        {
            var user = TokenManager.GetCurentUserbyToken(Request.Headers);
            
            return await _service.PutAsync(requestObject);
        }

        /// <summary>
        /// 修改t_pm_message数据表数据，支持批量修改
        /// </summary>
        /// <param name="requestObject">返回响应结果</param>
        /// <returns></returns>
        [HttpPut]
        [Route("[action]")]
        public async Task<ResponseObject<bool>> Read(RequestPut<TpmmessageEditModel> requestObject)
        {
            var user = TokenManager.GetCurentUserbyToken(Request.Headers);

            return await _service.ReadAsync(requestObject);
        }

        /// <summary>
        /// 删除t_pm_message数据表数据
        /// </summary>
        /// <param name="requestObject">返回响应结果</param>
        [HttpDelete]
        public async Task<ResponseObject<bool>> Delete(RequestDelete<DeleteModel> requestObject)
        {
            return await _service.DeleteAsync(requestObject);
        }
    }
}
